package com.klhappy.houyuan.modle;

import android.content.Context;

import com.klhappy.houyuan.bean.ConfirmBean;
import com.klhappy.houyuan.constant.KeyConstant;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.utils.BaseModel;
import com.klhappy.houyuan.utils.ConfigManager;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Created by MrPu on 15/11/24.
 */
public class HouYuanModle extends BaseModel{

    private Map<String ,String> params = new HashMap<>();

    private ConfigManager manage;

    private String cookie;

    public HouYuanModle(Context context) {
        super(context);
        manage = new ConfigManager(context);
        cookie = manage.get(KeyConstant.session, cookie);
    }
    //获取首页商品
    public void getGoods(){
        String path = UrlConstant.GOODS_URL;

        Callback(path ,params);
    }
    //获取首页商品种类
    public  void getGoodsType(){
        String path = UrlConstant.CATOGY_URL;

        Callback(path ,params);
    }
    //加入购物车
    public void setOrder(JSONObject object){
        String path = UrlConstant.ADDSHOP_URL;

        params.put("goodsInfo" ,object + "");
        Callback(path, params ,cookie);
    }
    //按种类获取商品
    public void getGoodsIn(int id){
        String path = UrlConstant.GOODS_URL;

        params.put("ca_id" ,id + "");
        Callback(path, params);
    }
    //单个商品详情
    public void getGoodDetail(String goodId){
        String path = UrlConstant.GOODS_DETAIL_URL;

        params.put("g_id" ,goodId);
        Callback(path, params);
    }
    //获取派送时间
    public void getTime(){
        String path = UrlConstant.TIME_URL;

        Callback(path ,params);
    }
    //单个订单详情
    public void getrder(String or_id){
        String path = UrlConstant.ORDER_DETAIL_URL;

        params.put("or_id" ,or_id);
        Callback(path ,params ,cookie);
    }
    //获取单个商品评论
    public void getComments(String id){
        String path = UrlConstant.COMMENTS_URL;

        params.put("g_id" ,id);
        Callback(path ,params ,cookie);
    }
    //获取加载刷新评论列表
    public void getNewComments(String id, String path){

        params.put("g_id" ,id);
        Callback(path, params, cookie);
    }
    //获取配送费
    public void getFee(String ammont){
        String path = UrlConstant.FEE_URL;

        params.put("or_amount" ,ammont);
        Callback(path ,params ,cookie);
    }
    //生成订单
    public void setConfirm(ConfirmBean confirmBean){
        String path = UrlConstant.BUIL_ORDER_URL;

        params.put("goodsInfo" ,confirmBean.getGoodsInfo() + "");
        if (!confirmBean.getPrevAddress().equals("") && confirmBean.getPrevAddress() != null){
            params.put("prevAddress" ,confirmBean.getPrevAddress());
        }else {
            params.put("newAddress" ,confirmBean.getNewAddress());
        }
        params.put("deliveryTime" ,confirmBean.getDeliveryTime());
        params.put("useCoupons" ,confirmBean.getUseCoupons() + "");
        params.put("order_remarks" ,confirmBean.getOrder_remarks());
        params.put("channel" ,confirmBean.getChannel());
        Callback(path ,params ,cookie);
    }
    //支付
    public void getCancel(String id ,String cancel){
        String path = UrlConstant.TOPAY_URL;

        params.put("id" ,id);
        params.put("channel" ,cancel);
        Callback(path ,params ,cookie);
    }
    //搜索商品
    public void getSearch(String key){
        String path = UrlConstant.SEARCH_URL;

        params.put("key" ,key);
        Callback(path ,params);
    }
    //获取默认地址
    public void getDeAddress(){
        String path = UrlConstant.DEADDRESS_URL;

        Callback(path ,params ,cookie);
    }
    //判断商品库存
    public void setTock(String id){
        String path = UrlConstant.STOCK_URL;

        params.put("g_id" ,id);
        Callback(path ,params ,cookie);
    }
}
